<?php
namespace Home\Controller;
class IndexController extends HomeController {
    public function index(){
        $this->assign('title','首页');
        $user = M('user');
        $data = $user->table('dota2_user_info ui, dota2_user u')->where('ui.ui_id=u.u_id and u.email="'.$_SESSION['email'].'"')->select();
        // dump($data);
        $this->assign('data',$data);
        //刀币商城
        $goods = M()->table('dota2_goods ')->join('dota2_goodsimg on  gi_g_id = g_id')->where('face = 1 and hot = 1')->limit('8')->select();
        $this->assign('goods',$goods);
        //风云榜
        $page = mt_rand(1,5);
        date_default_timezone_set("PRC");
        $showapi_appid = '30608';  
        $showapi_secret = '0d25d46999c74722b1e53b618b382adb'; 
        $paramArr = array(
             'showapi_appid'=> $showapi_appid,
             'typeId'=> "38",
             'space'=> "day",
             'key'=> "",
             'date'=> "",
             'page'=> $page
        );
        $param = createParam($paramArr,$showapi_secret);
        $url = 'http://route.showapi.com/254-1?'.$param; 
        $result = file_get_contents($url);
        $result = json_decode($result);
        $result = $result->showapi_res_body->pagebean->contentlist;
        $list = array();
        foreach($result as $k => $v){
            $list[$k] = object2array($result[$k]);
        }
        $this->assign('list',$list);
        $this->display();
    }
    public function logout(){
        session('email',null);
        session('nickname',null);
        session('uid',null);
        $this->success('注销成功',U('Index/index'));
    }   

    public function check_icon()
    {
        $user = M('user');
        $data = $user->field('icon')->table('dota2_user_info ui, dota2_user u')->where('ui.ui_id=u.u_id and u.email="'.$_SESSION['email'].'"')->select()[0]['icon'];
        $iconpath = '/Uploads/person_icon/';
        $iconpath .= substr($data,0,8).'/';
        if (!empty($data)) {
            echo $iconpath.$data;
        }
    }

}